package com.example.flshtarvel.controller;

import com.example.flshtarvel.service.ArticleLikeMapService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@RestController
public class ArticleLikeMapController {
    @Autowired
    ArticleLikeMapService articleLikeMapService;

    //信息点赞
    @GetMapping("/articleLike/{articleId}")
    public Map<String,Object> articleLike(@PathVariable("articleId")String articleId,HttpSession session){
        Map<String,Object> map = new HashMap<String,Object>();
        int result = articleLikeMapService.ArticleLike(articleId,(String)session.getAttribute("userId"));
        if(result==1){
            map.put("msg",1);
        }else{
            map.put("msg",0);
        }
        return map;
    }
    //取消点赞
    @GetMapping("/deleteArticleLike/{articleId}")
    public Map<String,Object> deleteArticleLike(@PathVariable("articleId")String articleId, HttpSession session){
        Map<String,Object> map = new HashMap<String,Object>();

        int result = articleLikeMapService.deleteArticleLike(articleId,(String)session.getAttribute("userId"));
        if(result >= 1){
            map.put("msg",1);
        }else{
            map.put("msg",0);
        }
        return map;
    }
    //查询点赞    根据信息id 用户id
    @GetMapping("/seleteArticleLike")
    public Map<String,Object> selectArticleLikeByArticleIdAndUserId(String articleId, String userId){
        Map<String,Object> map = new HashMap<String,Object>();
        //List<ArticleLikeMap> articleLikeMaps = articleLikeMapService.selectArticleLikeByArticleIdAndUserId(articleId,userId);
//        if(articleLikeMaps.size()==0||articleLikeMaps==null){
//            map.put("msg",0);
//        }else{
//            map.put("msg",1);
//        }
        return map;
    }

    //查询点赞数   根据信息id
    @GetMapping("/seleteArticleLikeCount")
    public Map<String,Object> selectArticleLikeByArticleId(String articleId){
        Map<String,Object> map = new HashMap<String,Object>();
        int result = articleLikeMapService.selectArticleLikeByArticleId(articleId);
        map.put("msg",1);
        map.put("count",result);
        return map;
    }



}
